import 'dart:io';

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:riki_push/enum/phone_platform.dart';
import 'package:riki_push/factory/riki_base_push.dart';
import 'package:riki_base_flutter/riki_base_flutter.dart';

/// 作者：宋佳宾
/// 日期：2021/4/17
/// 备注：oppo

class RikiOppoPush {
  static const MethodChannel _channel_oppo = const MethodChannel('riki_push_oppo');

  static Future<void> init({@required String appKey, @required String appSecret}) async {
    return await _channel_oppo.invokeMethod('initOppo', {
      "appSecret": appSecret,
      "appKey": appKey,
    });
  }

  /// 获取opppRid
  static Future<String> get oppoRid async {
    String oppoRegId = '';
    if (Platform.isAndroid && await RikiBasePush.phonePlatform == PhonePlatform.oppo) {
      oppoRegId = await _channel_oppo.invokeMethod('getOppoRegId');
    }
    LogUtil.v("oppoRegId是" + oppoRegId);
    return oppoRegId;
  }

  /// 申请oppo推送权限
  static Future<void> applyOppoPermission() async {
    if (Platform.isAndroid && await RikiBasePush.phonePlatform == PhonePlatform.oppo) {
      await _channel_oppo.invokeMethod('applyOppoPermission');
    }
  }

  /// 反初始化 oppoPush
  static Future<void> unInit() async {
    if (Platform.isAndroid && await RikiBasePush.phonePlatform == PhonePlatform.oppo) {
      return await _channel_oppo.invokeMethod('unInit');
    }
  }
}
